<?php
class WeiboController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
        //设置首页引用js
        $this->view->headScript()->appendFile($this->view->baseUrl().'/js/jquery-1.8.1.min.js');
        $this->view->headScript()->appendFile($this->view->baseUrl().'/js/masonry.pkgd.min.js');
        $this->view->headScript()->appendFile($this->view->baseUrl().'/js/imagesloaded.pkgd.min.js');
        $this->view->headScript()->appendFile($this->view->baseUrl().'/js/scroll.js');
        //设置首页引用css
        $this->view->headLink()->appendStylesheet($this->view->baseUrl().'/css/weibo.css');
    }

    public function indexAction()
    {
        // action body
        /*        $dbWeibo=new Application_Model_DbTable_Weibo();
                $res=$dbWeibo->getWeibo();
                $this->view->weibos=$res;*/
         //设置title
        $this->view->headTitle("微博汇");
        //设置关键词（seo）
        $this->view->headMeta()->appendName('keywords', "微博精选,微博玉石图片,微博玉石知识,珠宝图片");
        //设置描述（seo）
        $this->view->headMeta()->appendName('description','新浪微博珠宝玉石图片及知识精选。');
        $dbWeiboUser=new Application_Model_DbTable_WeiboUser();
        $users=$dbWeiboUser->getTopUsers();
        $this->view->users=$users;
        
        $config=new Zend_Config_Ini(APPLICATION_PATH."/configs/application.ini",'production');
        $db = Zend_Db::factory($config->resources->db);
        $selecter=$db->select()->from('txy_weibo')->order('id desc');
        $pageAdapter=new Zend_Paginator_Adapter_DbSelect($selecter);
        $paginator = new Zend_Paginator($pageAdapter);
        $paginator->setItemCountPerPage(16);
        $page=$this->_getParam('page');
        if($page>$paginator->count()){
            throw new Exception("page no found", "404");
        }
        $paginator->setCurrentPageNumber($page);
        $this->view->paginator = $paginator;
    }

    public function singlePageAction()
    {
        $id=$this->getRequest()->getParam('id');
        $dbWeibo=new Application_Model_DbTable_WeiboJoinUser();
        $res=$dbWeibo->getWeiboById($id);
        $this->view->weibo=$res;
        $c = Txy_Util_Weibo::getWeiboAccess();
        $ms  = $c->get_comments_by_sid($id);
        if(isset($ms['comments'])){
            $this->view->comments=$ms['comments'];
        }
        
        //设置title
        $this->view->headTitle("微博精选");
        //设置关键词（seo）
        $this->view->headMeta()->appendName('keywords', "珠宝玉石图片,玉石知识");
        //设置描述（seo）
        $this->view->headMeta()->appendName('description',$res['text']);
        $this->view->sideBar=1;
        //边栏热门文章列表
        $articleModel=new Application_Model_DbTable_Article();
        $this->view->hotArticles=$articleModel->getHotArticle(15);
        //边栏热门商品列表
        $itemsModel=new Application_Model_DbTable_TaobaoItems();
        $this->view->hotItems=$itemsModel->getSidebarHotItems();
        
    }
    
    public function masterAction(){
        $masterId=$this->getRequest()->getParam("masterId");
        $dbWeiboUser=new Application_Model_DbTable_WeiboUser();
        $master=$dbWeiboUser->getUserById($masterId);
        if(null==$master){
            throw new Exception("page no found", "404");
        }
        $this->view->headTitle($master['uname']." - 微博汇");
        //设置关键词（seo）
        $this->view->headMeta()->appendName('keywords', $master['uname'].",新浪微博精选 ,珠宝玉石知识,玉石图片");
        //设置描述（seo）
        $this->view->headMeta()->appendName('description','精选新浪微博用户'.$master['uname']."(".$master['description'].")");
        $this->view->master=$master;
        $this->view->masterId=$masterId;
        $config=new Zend_Config_Ini(APPLICATION_PATH."/configs/application.ini",'production');
        $db = Zend_Db::factory($config->resources->db);
        $selecter=$db->select()->from('txy_weibo')->where('uid='.$masterId)->order('id desc');
        $pageAdapter=new Zend_Paginator_Adapter_DbSelect($selecter);
        $paginator = new Zend_Paginator($pageAdapter);
        $paginator->setItemCountPerPage(16);
        $page=$this->_getParam('page');
        if($page>$paginator->count()){
            throw new Exception("page no found", "404");
        }
        $paginator->setCurrentPageNumber($page);
        $this->view->paginator = $paginator;
    }


}



